#ifndef DASHBOARD_H
#define DASHBOARD_H

#include <QWidget>
#include <QColor>
#include <QTimer>
#include <QFont>

class QLCDNumber;

#ifdef quc
#if (QT_VERSION < QT_VERSION_CHECK(5,7,0))
#include <QtDesigner/QDesignerExportWidget>
#else
#include <QtUiPlugin/QDesignerExportWidget>
#endif

class QDESIGNER_WIDGET_EXPORT GaugeSpeed : public QWidget
#else
class Dashboard : public QWidget
#endif

{
    Q_OBJECT
    Q_PROPERTY(double minValue READ getMinValue WRITE setMinValue)
    Q_PROPERTY(double maxValue READ getMaxValue WRITE setMaxValue)
    Q_PROPERTY(double value READ getValue WRITE setValue)
    Q_PROPERTY(int precision READ getPrecision WRITE setPrecision)
    Q_PROPERTY(int scaleMajor READ getScaleMajor WRITE setScaleMajor)
    Q_PROPERTY(int scaleMinor READ getScaleMinor WRITE setScaleMinor)
    Q_PROPERTY(int startAngle READ getStartAngle WRITE setStartAngle)
    Q_PROPERTY(int endAngle READ getEndAngle WRITE setEndAngle)
    Q_PROPERTY(bool animation READ getAnimation WRITE setAnimation)
    Q_PROPERTY(double animationStep READ getAnimationStep WRITE setAnimationStep)
    Q_PROPERTY(int ringWidth READ getRingWidth WRITE setRingWidth)
    Q_PROPERTY(int ringStartPercent READ getRingStartPercent WRITE setRingStartPercent)
    Q_PROPERTY(int ringMidPercent READ getRingMidPercent WRITE setRingMidPercent)
    Q_PROPERTY(int ringEndPercent READ getRingEndPercent WRITE setRingEndPercent)
    Q_PROPERTY(QColor ringColorStart READ getRingColorStart WRITE setRingColorStart)
    Q_PROPERTY(QColor ringColorMid READ getRingColorMid WRITE setRingColorMid)
    Q_PROPERTY(QColor ringColorEnd READ getRingColorEnd WRITE setRingColorEnd)
    Q_PROPERTY(QColor pointerColor READ getPointerColor WRITE setPointerColor)
    Q_PROPERTY(QColor textColor READ getTextColor WRITE setTextColor)
public:
    explicit Dashboard(QWidget *parent = 0);
    ~Dashboard();
    void setcurrentvalue(double value);
    void settextvalue(QString text);
protected:
    //void resizeEvent(QResizeEvent *);
    void paintEvent(QPaintEvent *);
    void drawRing(QPainter *painter);
    void drawScale(QPainter *painter);
    void drawScaleNum(QPainter *painter);
    void drawPointer(QPainter *painter);
    void drawValue(QPainter *painter);

private slots:
    void updateValue();

private:
    QString textValue;
    double minValue = -10;                //最小值
    double maxValue = 100;                //最大值
    double value = 40;                   //目标值
    int precision = 2;                  //精确度,小数点后几位

    int scaleMajor = 6;                 //大刻度数量
    int scaleMinor = 60;                 //小刻度数量
    int startAngle = 45;                 //开始旋转角度
    int endAngle = 45;                   //结束旋转角度

    bool animation = 0;                 //是否启用动画显示
    double animationStep = 1;           //动画显示时步长

    int ringWidth = 7;                  //圆环宽度
    int ringStartPercent=10;           //第一圆环比例
    int ringMidLeftPercent=10;
    int ringMidPercent=60;             //第二圆环比例
    int ringMidRightPercent=10;
    int ringEndPercent=10;             //第三圆环比例

    QColor ringColorStart= QColor(255,0,0,255);          //第一圆环颜色
    QColor ringColorMidLeft = QColor(250,211,0,144);
    QColor ringColorMid = QColor(0,255,0,255);            //第二圆环颜色
    QColor ringColorMidRight = QColor(250,211,0,144);
    QColor ringColorEnd = QColor(255,0,0,255);            //第三圆环颜色

    QColor pointerColor = Qt::red;            //指针颜色
    QColor textColor = Qt::red;//Qt::darkGreen;               //文字颜色

    bool reverse;                   //是否往回走
    double currentValue = 40;            //当前值
    QTimer *timer;                  //定时器绘制动画
    QLCDNumber *lcd;                //数码管

public:
    double getMinValue()            const;
    double getMaxValue()            const;
    double getValue()               const;
    int getPrecision()              const;

    int getScaleMajor()             const;
    int getScaleMinor()             const;
    int getStartAngle()             const;
    int getEndAngle()               const;

    bool getAnimation()             const;
    double getAnimationStep()       const;

    int getRingWidth()              const;
    int getRingStartPercent()       const;
    int getRingMidPercent()         const;
    int getRingEndPercent()         const;

    QColor getRingColorStart()      const;
    QColor getRingColorMid()        const;
    QColor getRingColorEnd()        const;

    QColor getPointerColor()        const;
    QColor getTextColor()           const;

    QSize sizeHint()                const;
    QSize minimumSizeHint()         const;

public Q_SLOTS:
    //设置范围值
    void setRange(double minValue, double maxValue);
    void setRange(int minValue, int maxValue);

    //设置最大最小值
    void setMinValue(double minValue);
    void setMaxValue(double maxValue);

    //设置目标值
    void setValue(double value);
    void setValue(int value);
    void setValue(const QString &value);

    //设置精确度
    void setPrecision(int precision);

    //设置主刻度数量
    void setScaleMajor(int scaleMajor);
    //设置小刻度数量
    void setScaleMinor(int scaleMinor);
    //设置开始旋转角度
    void setStartAngle(int startAngle);
    //设置结束旋转角度
    void setEndAngle(int endAngle);

    //设置是否启用动画显示
    void setAnimation(bool animation);
    //设置动画显示的步长
    void setAnimationStep(double animationStep);

    //设置饼圆宽度
    void setRingWidth(int ringWidth);

    //设置三个圆环所占比例
    void setRingStartPercent(int ringStartPercent);
    void setRingMidPercent(int ringMidPercent);
    void setRingEndPercent(int ringEndPercent);

    //设置三个圆环颜色
    void setRingColorStart(const QColor &ringColorStart);
    void setRingColorMid(const QColor &ringColorMid);
    void setRingColorEnd(const QColor &ringColorEnd);

    //设置指针颜色
    void setPointerColor(const QColor &pointerColor);
    //设置文本颜色
    void setTextColor(const QColor &textColor);

Q_SIGNALS:
    void valueChanged(int value);
};


#endif // DASHBOARD_H
